:-lib(ic).
:-lib(ic_symbolic).

/*Q2.1*/
/*m(Pays,Couleur,Boisson,Voiture,Animal,Numero)*/

/*Définitions des domaines symboliques*/
:- local domain(pays(angleterre,espagne,ukraine,norvege,japon)).
:- local domain(couleur(rouge,vert,jaune,blanc,bleu)).
:- local domain(boisson(jus_Orange,lait,cafe,the,eau)).
:- local domain(voiture(toyota,bmw,datsum,honda,ford)).
:- local domain(animal(chien,serpents,renard,cheval,zebre)).
:- local domain(numero(1,2,3,4,5)).

/*Q2.2*/
domaines_maison(m(Pays,Couleur,Boisson,Voiture,Animal,Numero)):-
	Pays &:: pays,
	Couleur &:: couleur,
	Boisson &::boisson,
	Voiture &:: voiture,
	Animal &:: animal,
	Numero &:: numero.

/*Q2.3*/
rue(Rue):-
	Rue = [
	m(P1,C1,B1,V1,A1,1),
	m(P2,C2,B2,V2,A2,2),
	m(P3,C3,B3,V3,A3,3),
	m(P4,C4,B4,V4,A4,4),
	m(P5,C5,B5,V5,A5,5)
	],
	domaines_maison(m(P1,C1,B1,V1,A1,1)),
	domaines_maison(m(P2,C2,B2,V2,A2,2)),
	domaines_maison(m(P3,C3,B3,V3,A3,3)),
	domaines_maison(m(P4,C4,B4,V4,A4,4)),
	domaines_maison(m(P5,C5,B5,V5,A5,5)),
	ic_symbolic:alldifferent([P1,P2,P3,P4,P5]),
	ic_symbolic:alldifferent([C1,C2,C3,C4,C5]),
	ic_symbolic:alldifferent([V1,V2,V3,V4,V5]),
	ic_symbolic:alldifferent([A1,A2,A3,A4,A5]),
	ic_symbolic:alldifferent([B1,B2,B3,B4,B5]).

/*
R = [m(_326{[angleterre, espagne, ukraine, norvege, japon]}, _430{[rouge, vert, jaune, blanc, bleu]}, _534{[jus_Orange, lait, cafe, the, eau]}, _638{[toyota, bmw, datsum, honda, ford]}, _742{[chien, serpents, renard, cheval, zebre]}, _846{[1, 2, 3, 4, 5]}), m(_957{[angleterre, espagne, ukraine, norvege, japon]}, _1061{[rouge, vert, jaune, blanc, bleu]}, _1165{[jus_Orange, lait, cafe, the, eau]}, _1269{[toyota, bmw, datsum, honda, ford]}, _1373{[chien, serpents, renard, cheval, zebre]}, _1477{[1, 2, 3, 4, 5]}), m(_1588{[angleterre, espagne, ukraine, norvege, japon]}, _1692{[rouge, vert, jaune, blanc, bleu]}, _1796{[jus_Orange, lait, cafe, the, eau]}, _1900{[toyota, bmw, datsum, honda, ford]}, _2004{[chien, serpents, renard, cheval, zebre]}, _2108{[1, 2, 3, 4, 5]}), m(_2219{[angleterre, espagne, ukraine, norvege, japon]}, _2323{[rouge, vert, jaune, blanc, bleu]}, _2427{[jus_Orange, lait, cafe, the, eau]}, _2531{[toyota, bmw, datsum, honda, ford]}, _2635{[chien, serpents, renard, cheval, zebre]}, _2739{[1, 2, 3, 4, 5]}), m(_2850{[angleterre, espagne, ukraine, norvege, japon]}, _2954{[rouge, vert, jaune, blanc, bleu]}, _3058{[jus_Orange, lait, cafe, the, eau]}, _3162{[toyota, bmw, datsum, honda, ford]}, _3266{[chien, serpents, renard, cheval, zebre]}, _3370{[1, 2, 3, 4, 5]})]

There are 36 delayed goals. Do you want to see them? (y/n) 

Delayed goals:
	ic_symbolic : sync_ic_symbolic(_326{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_304{1 .. 5}, eclipse : pays))
	ic_symbolic : sync_ic_symbolic(_430{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_408{1 .. 5}, eclipse : couleur))
	ic_symbolic : sync_ic_symbolic(_534{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_512{1 .. 5}, eclipse : boisson))
	ic_symbolic : sync_ic_symbolic(_638{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_616{1 .. 5}, eclipse : voiture))
	ic_symbolic : sync_ic_symbolic(_742{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_720{1 .. 5}, eclipse : animal))
	ic_symbolic : sync_ic_symbolic(_846{[1, 2, 3, 4, 5]}, ic_symbolic(_824{1 .. 5}, eclipse : numero))
	ic_symbolic : sync_ic_symbolic(_957{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_935{1 .. 5}, eclipse : pays))
	ic_symbolic : sync_ic_symbolic(_1061{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_1039{1 .. 5}, eclipse : couleur))
	ic_symbolic : sync_ic_symbolic(_1165{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_1143{1 .. 5}, eclipse : boisson))
	ic_symbolic : sync_ic_symbolic(_1269{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_1247{1 .. 5}, eclipse : voiture))
	ic_symbolic : sync_ic_symbolic(_1373{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_1351{1 .. 5}, eclipse : animal))
	ic_symbolic : sync_ic_symbolic(_1477{[1, 2, 3, 4, 5]}, ic_symbolic(_1455{1 .. 5}, eclipse : numero))
	ic_symbolic : sync_ic_symbolic(_1588{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_1566{1 .. 5}, eclipse : pays))
	ic_symbolic : sync_ic_symbolic(_1692{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_1670{1 .. 5}, eclipse : couleur))
	ic_symbolic : sync_ic_symbolic(_1796{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_1774{1 .. 5}, eclipse : boisson))
	ic_symbolic : sync_ic_symbolic(_1900{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_1878{1 .. 5}, eclipse : voiture))
	ic_symbolic : sync_ic_symbolic(_2004{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_1982{1 .. 5}, eclipse : animal))
	ic_symbolic : sync_ic_symbolic(_2108{[1, 2, 3, 4, 5]}, ic_symbolic(_2086{1 .. 5}, eclipse : numero))
	ic_symbolic : sync_ic_symbolic(_2219{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_2197{1 .. 5}, eclipse : pays))
	ic_symbolic : sync_ic_symbolic(_2323{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_2301{1 .. 5}, eclipse : couleur))
	ic_symbolic : sync_ic_symbolic(_2427{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_2405{1 .. 5}, eclipse : boisson))
	ic_symbolic : sync_ic_symbolic(_2531{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_2509{1 .. 5}, eclipse : voiture))
	ic_symbolic : sync_ic_symbolic(_2635{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_2613{1 .. 5}, eclipse : animal))
	ic_symbolic : sync_ic_symbolic(_2739{[1, 2, 3, 4, 5]}, ic_symbolic(_2717{1 .. 5}, eclipse : numero))
	ic_symbolic : sync_ic_symbolic(_2850{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_2828{1 .. 5}, eclipse : pays))
	ic_symbolic : sync_ic_symbolic(_2954{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_2932{1 .. 5}, eclipse : couleur))
	ic_symbolic : sync_ic_symbolic(_3058{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_3036{1 .. 5}, eclipse : boisson))
	ic_symbolic : sync_ic_symbolic(_3162{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_3140{1 .. 5}, eclipse : voiture))
	ic_symbolic : sync_ic_symbolic(_3266{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_3244{1 .. 5}, eclipse : animal))
	ic_symbolic : sync_ic_symbolic(_3370{[1, 2, 3, 4, 5]}, ic_symbolic(_3348{1 .. 5}, eclipse : numero))
	ic_global : alldifferent([_304{1 .. 5}, _935{1 .. 5}, _1566{1 .. 5}, _2197{1 .. 5}, _2828{1 .. 5}], 1)
	ic_global : alldifferent([_408{1 .. 5}, _1039{1 .. 5}, _1670{1 .. 5}, _2301{1 .. 5}, _2932{1 .. 5}], 1)
	ic_global : alldifferent([_616{1 .. 5}, _1247{1 .. 5}, _1878{1 .. 5}, _2509{1 .. 5}, _3140{1 .. 5}], 1)
	ic_global : alldifferent([_720{1 .. 5}, _1351{1 .. 5}, _1982{1 .. 5}, _2613{1 .. 5}, _3244{1 .. 5}], 1)
	ic_global : alldifferent([_824{1 .. 5}, _1455{1 .. 5}, _2086{1 .. 5}, _2717{1 .. 5}, _3348{1 .. 5}], 1)
	ic_global : alldifferent([_512{1 .. 5}, _1143{1 .. 5}, _1774{1 .. 5}, _2405{1 .. 5}, _3036{1 .. 5}], 1)
Yes (0.00s cpu)



----------------------------
[eclipse 11]: rue(R).

R = [m(_295{[angleterre, espagne, ukraine, norvege, japon]}, _399{[rouge, vert, jaune, blanc, bleu]}, _503{[jus_Orange, lait, cafe, the, eau]}, _607{[toyota, bmw, datsum, honda, ford]}, _711{[chien, serpents, renard, cheval, zebre]}, 1), m(_880{[angleterre, espagne, ukraine, norvege, japon]}, _984{[rouge, vert, jaune, blanc, bleu]}, _1088{[jus_Orange, lait, cafe, the, eau]}, _1192{[toyota, bmw, datsum, honda, ford]}, _1296{[chien, serpents, renard, cheval, zebre]}, 2), m(_1465{[angleterre, espagne, ukraine, norvege, japon]}, _1569{[rouge, vert, jaune, blanc, bleu]}, _1673{[jus_Orange, lait, cafe, the, eau]}, _1777{[toyota, bmw, datsum, honda, ford]}, _1881{[chien, serpents, renard, cheval, zebre]}, 3), m(_2050{[angleterre, espagne, ukraine, norvege, japon]}, _2154{[rouge, vert, jaune, blanc, bleu]}, _2258{[jus_Orange, lait, cafe, the, eau]}, _2362{[toyota, bmw, datsum, honda, ford]}, _2466{[chien, serpents, renard, cheval, zebre]}, 4), m(_2635{[angleterre, espagne, ukraine, norvege, japon]}, _2739{[rouge, vert, jaune, blanc, bleu]}, _2843{[jus_Orange, lait, cafe, the, eau]}, _2947{[toyota, bmw, datsum, honda, ford]}, _3051{[chien, serpents, renard, cheval, zebre]}, 5)]

There are 30 delayed goals. Do you want to see them? (y/n) 

Delayed goals:
        ic_symbolic : sync_ic_symbolic(_295{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_273{1 .. 5}, eclipse : pays))
        ic_symbolic : sync_ic_symbolic(_399{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_377{1 .. 5}, eclipse : couleur))
        ic_symbolic : sync_ic_symbolic(_503{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_481{1 .. 5}, eclipse : boisson))
        ic_symbolic : sync_ic_symbolic(_607{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_585{1 .. 5}, eclipse : voiture))
        ic_symbolic : sync_ic_symbolic(_711{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_689{1 .. 5}, eclipse : animal))
        ic_symbolic : sync_ic_symbolic(_880{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_858{1 .. 5}, eclipse : pays))
        ic_symbolic : sync_ic_symbolic(_984{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_962{1 .. 5}, eclipse : couleur))
        ic_symbolic : sync_ic_symbolic(_1088{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_1066{1 .. 5}, eclipse : boisson))
        ic_symbolic : sync_ic_symbolic(_1192{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_1170{1 .. 5}, eclipse : voiture))
        ic_symbolic : sync_ic_symbolic(_1296{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_1274{1 .. 5}, eclipse : animal))
        ic_symbolic : sync_ic_symbolic(_1465{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_1443{1 .. 5}, eclipse : pays))
        ic_symbolic : sync_ic_symbolic(_1569{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_1547{1 .. 5}, eclipse : couleur))
        ic_symbolic : sync_ic_symbolic(_1673{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_1651{1 .. 5}, eclipse : boisson))
        ic_symbolic : sync_ic_symbolic(_1777{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_1755{1 .. 5}, eclipse : voiture))
        ic_symbolic : sync_ic_symbolic(_1881{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_1859{1 .. 5}, eclipse : animal))
        ic_symbolic : sync_ic_symbolic(_2050{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_2028{1 .. 5}, eclipse : pays))
        ic_symbolic : sync_ic_symbolic(_2154{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_2132{1 .. 5}, eclipse : couleur))
        ic_symbolic : sync_ic_symbolic(_2258{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_2236{1 .. 5}, eclipse : boisson))
        ic_symbolic : sync_ic_symbolic(_2362{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_2340{1 .. 5}, eclipse : voiture))
        ic_symbolic : sync_ic_symbolic(_2466{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_2444{1 .. 5}, eclipse : animal))
        ic_symbolic : sync_ic_symbolic(_2635{[angleterre, espagne, ukraine, norvege, japon]}, ic_symbolic(_2613{1 .. 5}, eclipse : pays))
        ic_symbolic : sync_ic_symbolic(_2739{[rouge, vert, jaune, blanc, bleu]}, ic_symbolic(_2717{1 .. 5}, eclipse : couleur))
        ic_symbolic : sync_ic_symbolic(_2843{[jus_Orange, lait, cafe, the, eau]}, ic_symbolic(_2821{1 .. 5}, eclipse : boisson))
        ic_symbolic : sync_ic_symbolic(_2947{[toyota, bmw, datsum, honda, ford]}, ic_symbolic(_2925{1 .. 5}, eclipse : voiture))
        ic_symbolic : sync_ic_symbolic(_3051{[chien, serpents, renard, cheval, zebre]}, ic_symbolic(_3029{1 .. 5}, eclipse : animal))
        ic_global : alldifferent([_273{1 .. 5}, _858{1 .. 5}, _1443{1 .. 5}, _2028{1 .. 5}, _2613{1 .. 5}], 1)
        ic_global : alldifferent([_377{1 .. 5}, _962{1 .. 5}, _1547{1 .. 5}, _2132{1 .. 5}, _2717{1 .. 5}], 1)
        ic_global : alldifferent([_585{1 .. 5}, _1170{1 .. 5}, _1755{1 .. 5}, _2340{1 .. 5}, _2925{1 .. 5}], 1)
        ic_global : alldifferent([_689{1 .. 5}, _1274{1 .. 5}, _1859{1 .. 5}, _2444{1 .. 5}, _3029{1 .. 5}], 1)
        ic_global : alldifferent([_481{1 .. 5}, _1066{1 .. 5}, _1651{1 .. 5}, _2236{1 .. 5}, _2821{1 .. 5}], 1)
Yes (0.09s cpu)

*/

/*
RueTest = [m(angleterre,rouge,jus_Orange,toyota,chien,1),m(espagne,vert,lait,bmw,serpents,2),m(ukraine,jaune,cafe,datsum,renard,3),m(norvege,blanc,the,honda,cheval,4),(japon,bleu,eau,ford,zebre,5)].

m(angleterre, rouge, jus_Orange, toyota, chien, 1)
m(espagne, vert, lait, bmw, serpents, 2)
m(ukraine, jaune, cafe, datsum, renard, 3)
m(norvege, blanc, the, honda, cheval, 4)
m(japon, bleu, eau, ford, zebre, 5)
*/

/*Q2.4*/
ecrit_maison(Rue):-
	(foreach(Elem,Rue)
	do
		writeln(Elem)
	).

/*Q2.5*/

getVarList([],[]).
getVarList([m(P,C,B,V,A,_)|R],[P,C,B,V,A|R2]):-getVarList(R,R2).

/*
L = [angleterre, rouge, jus_Orange, toyota, chien, espagne, vert, lait, bmw, serpents, ukraine, jaune, cafe, datsum, renard, norvege, ...]
Yes (0.00s cpu)
*/

labeling_symbolic([]).
labeling_symbolic([A|R]):-
	ic_symbolic:indomain(A),
	labeling_symbolic(R).

/*
[eclipse 24]: rue(R),getVarList(R,L),labeling_symbolic(L).

R = [m(angleterre, rouge, jus_Orange, toyota, chien, 1), m(espagne, vert, lait, bmw, serpents, 2), m(ukraine, jaune, cafe, datsum, renard, 3), m(norvege, blanc, the, honda, cheval, 4), m(japon, bleu, eau, ford, zebre, 5)]
L = [angleterre, rouge, jus_Orange, toyota, chien, 1, espagne, vert, lait, bmw, serpents, 2, ukraine, jaune, cafe, datsum, renard, 3, norvege, ...]
Yes (0.00s cpu, solution 1, maybe more) ?
*/

/*Q2.6*/
resoudre(Rue):-
	rue(Rue),getVarList(Rue,L),contrainte(Rue),labeling_symbolic(L),ecrit_maison(Rue).

/*
[eclipse 29]: resoudre(R).

m(angleterre, rouge, jus_Orange, toyota, chien, 1)
m(espagne, vert, lait, bmw, serpents, 2)
m(ukraine, jaune, cafe, datsum, renard, 3)
m(norvege, blanc, the, honda, cheval, 4)
m(japon, bleu, eau, ford, zebre, 5)

R = [m(angleterre, rouge, jus_Orange, toyota, chien, 1), m(espagne, vert, lait, bmw, serpents, 2), m(ukraine, jaune, cafe, datsum, renard, 3), m(norvege, blanc, the, honda, cheval, 4), m(japon, bleu, eau, ford, zebre, 5)]
*/

/*Q2.7*/
contrainte(R):-
	(foreach(Elem,R)
	do
		Elem = m(P,C,B,V,A,N),
		((P &= angleterre) #= (C &= rouge)),
		((P &= espagne) #= (A &= chien)),
		((C &= vert) #= (B &= cafe)),
		((P &= ukraine) #= (B &= the)),
		((V &= bmw) #= (A &= serpents)),
		((C &= jaune) #= (V &= toyota)),
		((B &= lait) #= (N &= 3)),
		((P &= norvege) #= (N &= 1)),
		((V &= honda) #= (B &= jus_Orange)),
		((P &= japon) #= (V &= datsum))
	).

/* 
Appel : 
rue(R),getVarList(R,L),Contrainte(R),labeling_symbolic(L).

R = [m(norvege, vert, cafe, ford, zebre, 1), m(japon, blanc, eau, datsum, renard, 2), m(angleterre, rouge, lait, bmw, serpents, 3), m(espagne, bleu, jus_Orange, honda, chien, 4), m(ukraine, jaune, the, toyota, cheval, 5)]
L = [norvege, vert, cafe, ford, zebre, japon, blanc, eau, datsum, renard, angleterre, rouge, lait, bmw, serpents, espagne, bleu, jus_Orange, honda, ...]
Yes (0.10s cpu, solution 1, maybe more) ? ;

R = [m(norvege, vert, cafe, ford, zebre, 1), m(japon, blanc, eau, datsum, renard, 2), m(angleterre, rouge, lait, bmw, serpents, 3), m(ukraine, jaune, the, toyota, cheval, 4), m(espagne, bleu, jus_Orange, honda, chien, 5)]
L = [norvege, vert, cafe, ford, zebre, japon, blanc, eau, datsum, renard, angleterre, rouge, lait, bmw, serpents, ukraine, jaune, the, toyota, ...]

etc...
*/

contrainte2(R):-
	(foreach(Elem1,R)
	do
		foreach(Elem2,R)
		do
			Elem1 = m(P1,C1,B1,V1,A1,N1),
			Elem2 = m(P2,C2,B2,V2,A2,N2),
			(C1 &= vert) #= ((N1 &= N2+1),
			(C2 &= blanc)
			 
